Game đuổi chó sa mạc lập trình bằng ngôn ngữ c#
19.235 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3 //using PathologicalGames;
4
5 public class Pillar : MonoBehaviour {
6 public float speed = 2f;
7 public GameManager gameManager;
8 public bool ok = false;
9
10 //public SpawnPool pool;
11
12 void Start () {
13 }
14
15 void SetOk()
16 {
17 ok = true;
18 gameManager.AddScore();
19 }
20
21 void Update () {
22 if (gameManager.isGameOver) return;
23 Vector3 pos = transform.position;
24 if (!ok && pos.x < -3f) SetOk();
25 if (pos.x < -5f)
26 {
27 //pool.Despawn(transform);
28 Destroy(gameObject);
29 }
30 //transform.position = Vector3.MoveTowards(transform.position, transform.position + 5f * Vector3.left, step);
31 //float step = speed * Time.deltaTime;
32 transform.position += Vector3.left * Time.deltaTime * speed;
33 }
34 }
2 using System.Collections;
3 //using PathologicalGames;
4
5 public class Pillar : MonoBehaviour {
6 public float speed = 2f;
7 public GameManager gameManager;
8 public bool ok = false;
9
10 //public SpawnPool pool;
11
12 void Start () {
13 }
14
15 void SetOk()
16 {
17 ok = true;
18 gameManager.AddScore();
19 }
20
21 void Update () {
22 if (gameManager.isGameOver) return;
23 Vector3 pos = transform.position;
24 if (!ok && pos.x < -3f) SetOk();
25 if (pos.x < -5f)
26 {
27 //pool.Despawn(transform);
28 Destroy(gameObject);
29 }
30 //transform.position = Vector3.MoveTowards(transform.position, transform.position + 5f * Vector3.left, step);
31 //float step = speed * Time.deltaTime;
32 transform.position += Vector3.left * Time.deltaTime * speed;
33 }
34 }
using PathologicalGames;
public SpawnPool pool;
pool.Despawn(transform);
transform.position = Vector3.MoveTowards(transform.position, transform.position + 5f * Vector3.left, step);
float step = speed * Time.deltaTime;